<?php 

//tim kiem
$flag=isset($_REQUEST['SO_tim' ])?$_REQUEST['SO_tim' ]:"";
$sea =isset($_REQUEST['SO_sea' ])?$_REQUEST['SO_sea' ]:"";
$sea2=isset($_REQUEST['SO_sea2'])?$_REQUEST['SO_sea2']:"";
$sea3=isset($_REQUEST['SO_sea3'])?$_REQUEST['SO_sea3']:"";
$sea4=isset($_REQUEST['SO_sea4'])?$_REQUEST['SO_sea4']:"";
$sea5=isset($_REQUEST['SO_sea5'])?$_REQUEST['SO_sea5']:"";
//end tim kiem
//sap xep
$kieu=isset($_REQUEST['SO_kieu'])?$_REQUEST['SO_kieu']:"DESC";
$cot =isset($_REQUEST['SO_cot' ])?$_REQUEST['SO_cot' ]:"id";
if($cot=='id')
$cot='`key`';
if($cot=='ac')
$cot2='`name`';
if($cot=='point')
$cot3='`point`';
if($cot=='ty')
$cot4='`type`';
if($cot=='up')
$cot5='`update`';
$sub_sql='';
if( $sea!=''){
    $cot='point.`key`';
    $sub_sql.=' and '.$cot." Like '".$sea."'";
}
if($sea2!=''){
    $cot2='account.`name`';
    $sub_sql.=' and ' .$cot2." Like '%".$sea2."%'";
}
if($sea3!=''){
    $cot3='point.`point`';
	$sub_sql.=' and '.$cot3." Like '%".$sea3."%'";
}
if($sea4!=''){
    $cot4='point.`type`';
	$sub_sql.=' and '.$cot4." Like '%".$sea4."%'";
	}
if($sea5!=''){
    $cot5='point.`update`';
	$sub_sql.=' and '.$cot5." Like '%".$sea5."%'";
}
//end sap xep
##############################################################
include("../JO_02_function.php");
include("../JO_01_configuration.php");
$JO_MySQL = new mysqli( $JO_DB_host, $JO_DB_user, $JO_DB_password, $JO_DB_database );
$JO_MySQL -> query( "SET subS 'UTF8'" );
if($kieu!='')
{   
	if($kieu=="DESC")  
	{
?>
<table>                 <input type="hidden" value="<?=$sea?>" id="sea" />
                        <input type="hidden" value="<?=$sea2?>" id="sea2" />
                        <input type="hidden" value="<?=$sea3?>" id="sea3" />
                        <input type="hidden" value="<?=$sea4?>" id="sea4" />
                        <input type="hidden" value="<?=$sea5?>" id="sea5" />
					<tr>
                        <th><span id="id"   onclick="sorting('ASC','id','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"     style="cursor:pointer">key	         	</span></th>
                        <th><span id="bugs" onclick="sorting('ASC','ac','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"    style="cursor:pointer">account	</span></th>
                        <th><span id="sub"  onclick="sorting('ASC','point','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"     style="cursor:pointer">point	            </span></th>
                        <th ><span id="add"  onclick="sorting('ASC','ty','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"   style="cursor:pointer">type	            </span></th>  
                        <th colspan="2"><span id="add"  onclick="sorting('ASC','up','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"   style="cursor:pointer">update</span></th>
                        <th></th>
                        </th>
                    </tr>
                    <tr>
                         <td><input type="text" id="txt_id"       value=""  style="width:20px !important" onkeypress="searchKeyPress(event,'id')" onclick="xoa()"/></td>		
                        <td><input type="text" 	id="txt_acc"      value="" style="width:80px !important" onkeypress="searchKeyPress(event,'acc')" onclick="xoa2()"/></td>
                        <td ><input type="text" id="txt_point"    value="" style="width:20px !important"  onkeypress="searchKeyPress(event,'point')" onclick="xoa3 ()"/></td>
                         <td><input type="text" id="txt_ty"    value="" 			 	 style="width:170px !important" onkeypress="searchKeyPress(event,'type')" onclick="xoa4()"/></td>
                        <td colspan="2"><input type="text" id="txt_up" value=""  	 style="width:100px !important"  onkeypress="searchKeyPress(event,'up')" onclick="xoa5()"/></td>
                    <td class="btnadd"><span style="cursor:pointer">Add</span>	
                    </tr>
                <!--load data-->
				   <?php 
				   $querycount="
		                  	SELECT	account.identifier AS `name`,point.*
                            FROM	account RIGHT OUTER JOIN point ON account.`key` = point.account
                            WHERE	`point`.`delete` is null ".$sub_sql;
            $recordSetnum = JO_query( $querycount );
			$total=$recordSetnum->num_rows;
			$page=1;
			$limit=10;
			if(($total%$limit)!=0) {$numpages=(int)($total/$limit)+1;}
			else                   {$numpages=$total/$limit;}
			if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
			$vt=(($page-1)*$limit);
                        $query = "
                            SELECT	account.identifier AS `name`,point.*
                            FROM	account RIGHT OUTER JOIN point ON account.`key` = point.account
                            WHERE	`point`.`delete` is null ".$sub_sql." order by ".$cot." ASC Limit $vt,$limit
                        ";
                        
						$recordSet = JO_query( $query );
						if(!$recordSet -> num_rows)
						echo '<tr><td colspan=7>Không Có Dữ Liệu Phù Hợp</td></tr>';
                        if( $recordSet -> num_rows ) 
                        while($record = $recordSet -> fetch_array( ))
						{
                   ?>
					<tr>
                        <td><?=$record['key' ]==""?"Chưa Có Thông Tin":$record['key'	 ]?></td>
                        <td><?=$record['name'	 ]==""?"Chưa Có Thông Tin":$record['name'	 ]?></td>
                        <td><?=$record['point'	 ]==""?"Chưa Có Thông Tin":$record['point'	]?></td>
                        <td><?=$record['type']==""?"Chưa Có Thông Tin":$record['type']?></td>
                        <td><?=$record['update' ]==""?"Chưa Có Thông Tin":$record['update'	 ]?></td>
                        <td></td>
                        <td class="btnedit"><span style="cursor:pointer">Edit</span></td>
                    </tr>
<?php  					}
?>
          <tr >
            <td style="text-align: center;border-bottom: 0px" colspan="5"><?
                if($numpages>1){
                    if($page>2){
                    ?>
              <a href="#" onclick="sorting('DESC','id','1');">◀</a>
              <?
                    }
                    if($page>1){
                    ?>
              <a href="#" onclick="sorting('DESC','id','<?=($page-1)?>');">◁</a>
              <?
                    }
                    if($page-4>1) echo "...";
                    for($i=$page-4;$i<=($page-1);$i++){
                        if($i>0){
                        ?>
              <a href="#" onclick="sorting('DESC','id','<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    echo  "<b style='color=#ffffff;'>".$page."</b>";
                    for($i=$page+1;$i<=($page+4);$i++){
                        if($i<=$numpages){
                        ?>
              <a href="#" onclick="sorting('DESC','id','<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    if($page+4<$numpages) echo "...";
                    if($page<$numpages){
                    ?>
              <a href="#" onclick="sorting('DESC','id','<?=($page+1) ?>');">▷</a>
              <?
                    }
                    if($page<($numpages-1)){
                    ?>
              <a href="#" onclick="sorting('DESC','id','<?=$numpages ?>');">▶</a>
              <?
                    }
                }
                 ?></td>
          </tr>
<?php
	}if($kieu=='ASC')
	{
?>
	<table>
                        <input type="hidden" value="<?=$sea?>" id="sea" />
                        <input type="hidden" value="<?=$sea2?>" id="sea2" />
                        <input type="hidden" value="<?=$sea3?>" id="sea3" />
                        <input type="hidden" value="<?=$sea4?>" id="sea4" />
                        <input type="hidden" value="<?=$sea5?>" id="sea5" />
						<tr>
                        <th><span id="id"   onclick="sorting('DESC','id','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"     style="cursor:pointer">key	         	</span></th>
                        <th><span id="bugs" onclick="sorting('DESC','ac','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"    style="cursor:pointer">acount	</span></th>
                        <th><span id="sub"  onclick="sorting('DESC','point','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"     style="cursor:pointer">point	            </span></th>
                        <th ><span id="add"  onclick="sorting('DESC','ty','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"   style="cursor:pointer">type	            </span></th>  
                        <th colspan="2"><span id="add"  onclick="sorting('ASC','up','<?=isset($_REQUEST['Page'])?$_REQUEST['Page']:"1"?>')"   style="cursor:pointer">update</span></th>
                        <th></th>
                    </tr>
                    <tr>
                         <td><input type="text" id="txt_id"       value=""  style="width:20px !important" onkeypress="searchKeyPress(event,'id')" onclick="xoa()"/></td>		
                        <td><input type="text" 	id="txt_acc"      value="" style="width:80px !important" onkeypress="searchKeyPress(event,'acc')" onclick="xoa2()"/></td>
                        <td ><input type="text" id="txt_point"    value="" style="width:20px !important"  onkeypress="searchKeyPress(event,'poin')" onclick="xoa3 ()"/></td>
                         <td><input type="text" id="txt_ty"    value="" 			 	 style="width:170px !important" onkeypress="searchKeyPress(event,'ty')" onclick="xoa4()"/></td>
                        <td colspan="2"><input type="text" id="txt_up" value=""  	 style="width:100px !important"  onkeypress="searchKeyPress(event,'up')" onclick="xoa5()"/></td>
                    <td class="btnadd"><span style="cursor:pointer">Add</span>	
                    </tr>
                <!--load data-->
				   <?php  
				     $querycount="
			SELECT * FROM `point` WHERE `delete` is NULL ".$sub_sql."
";
            $recordSetnum = JO_query( $querycount );
			$total=$recordSetnum->num_rows;
            $page=1;
			$limit=10;
			if(($total%$limit)!=0) {$numpages=(int)($total/$limit)+1;}
			else                   {$numpages=$total/$limit;}
			if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
			$vt=(($page-1)*$limit);
                        $query = "
                            SELECT	account.identifier AS `name`,point.*
                            FROM	account RIGHT OUTER JOIN point ON account.`key` = point.account
                            WHERE	`point`.`delete` is null ".$sub_sql." order by ".$cot." DESC Limit $vt,$limit
                        ";
                        $recordSet = JO_query( $query );
						if(!$recordSet -> num_rows)
						echo '<tr><td colspan=7>Không Có Dữ Liệu Phù Hợp</td></tr>';
                        if( $recordSet -> num_rows ) 
                        while($record = $recordSet -> fetch_array( ))
						{
                   ?>
					<tr>
                        <td><?=$record['key'	 ]==""?"Chua Có Thông Tin":$record['key'	 ]?></td>
                        <td><?=$record['name'	 ]==""?"Chua Có Thông Tin":$record['name'	 ]?></td>
                        <td><?=$record['point'	 ]==""?"Chua Có Thông Tin":$record['point'	]?></td>
                        <td><?=$record['type']==""?"Chua Có Thông Tin":$record['update']?></td>
                        <td><?=$record['update'	 ]==""?"Chua Có Thông Tin":$record['update'	 ]?></td>
                        <td></td>
                        <td class="btnedit"><span style="cursor:pointer">Edit</span></td>
                    </tr>
<?php		
						}?>
          <tr >
            <td style="text-align: center;border-bottom: 0px"  colspan="5"><?
                if($numpages>1){
                    if($page>2){
                    ?>
              <a href="#" onclick="sorting('ASC','id','1');">◀</a>
              <?
                    }
                    if($page>1){
                    ?>
              <a href="#" onclick="sorting('ASC','id','<?=($page-1)?>');">◁</a>
              <?
                    }
                    if($page-4>1) echo "...";
                    for($i=$page-4;$i<=($page-1);$i++){
                        if($i>0){
                        ?>
              <a href="#" onclick="sorting('ASC','id','<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    echo  "<b style='color=#ffffff;'>".$page."</b>";
                    for($i=$page+1;$i<=($page+4);$i++){
                        if($i<=$numpages){
                        ?>
              <a href="#" onclick="sorting('ASC','id','<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    if($page+4<$numpages) echo "...";
                    if($page<$numpages){
                    ?>
              <a href="#" onclick="sorting('ASC','id','<?=($page+1) ?>');">▷</a>
              <?
                    }
                    if($page<($numpages-1)){
                    ?>
              <a href="#" onclick="sorting('ASC','id','<?=$numpages ?>');">▶</a>
              <?
                    }
                }
                 ?></td>
          </tr>
<?php
	}
}
?>	
 <script>
function sorting(k,f,p){
            var sea=escape(_utf8_encode ($('#sea').val()));
			var sea2=escape(_utf8_encode($('#sea2').val()));
			var sea3=escape(_utf8_encode($('#sea3').val()));
			var sea4=escape(_utf8_encode($('#sea4').val()));
			var sea5=escape(_utf8_encode($('#sea5').val()));
            var url='JO_71_SO/SO_21_01_point.php?SO_kieu='+k+'&Page='+p;
            if(sea!='')  {url+="&SO_sea="+sea;   }
			if(sea2!='') {url+="&SO_sea2="+sea2;}
			if(sea3!='') {url+="&SO_sea3="+sea3; }
			if(sea4!='') {url+="&SO_sea4="+sea4; }
            if(sea5!='') {url+="&SO_sea5="+sea5; }
            $("#load_contend").load(url,10000,function(){
					initbtnedit()
					initbtnadd()
				});
	}
	/*$("span").click(
		function(){
		alert('a');
			//sorting('ASC',$(this).attr("id"),'<?//=$_REQUEST['Page']?>')
		}
	);*/
	function move()
	{
		if($("#tmp").length){
			$("#tmp").remove();
		}	
	}
	function move2()
	{
		if($("#tbp").length){
			$("#tbp").remove();
		}	
	}
	function submitform(F)
		{
			document.forms[F].submit();
		}
    function doi_hinh(){
}
	function show()
		{	
		if($("#extendcontent").is(":hidden")){
			$("#extendcontent").show();
		}else{
			$("#extendcontent").hide();
		}
		}
</script>